﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PlayingCardRecord
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            Result = new ObservableCollection<people>()
            {
            };
            this.datagrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(this.dataGridEquipment_LoadingRow);

        }

        private ObservableCollection<people> _Result;
        public ObservableCollection<people> Result 
        {
            get { return _Result; }
            set {
                _Result = value;
                if (PropertyChanged != null)//有改变
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Result"));
                }
            } 
        }

        private void dataGridEquipment_LoadingRow(object sender, DataGridRowEventArgs e)

        {

            e.Row.Header = e.Row.GetIndex() + 1;

        }

        public event PropertyChangedEventHandler PropertyChanged;


        private void datagrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            int ixiaozhou = 0, ixiaochen = 0, ixiaoai = 0;
            foreach (var item in Result)
            {
                ixiaozhou += item.zhou;
                ixiaochen += item.chen;
                ixiaoai += item.ai;
            }
            xiaozhou.Text = ixiaozhou.ToString();
            xiaochen.Text = ixiaochen.ToString();
            xiaoai.Text = ixiaoai.ToString();
        }
    }

    public class people
    {
        public int zhou { get; set; }
        public int chen { get; set; }
        public int ai { get; set; }
    }
}
